package com.itcam.kafka.controller;

import com.alibaba.fastjson.JSON;
import com.itcam.kafka.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : Cammy.Wu
 */

@RestController
public class KafkaDemoController {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    @GetMapping("/kafka")
    public String kafka() {
        // kafkaTemplate.send("itcam_topic", "i am a loser");

        User user = new User();
        user.setName("Cammy");
        user.setAge(18);

        kafkaTemplate.send("user_topic", JSON.toJSONString(user));

        return "ok";
    }
}
